text: Support reverse selection
authorMatthias Clasen <mclasen@redhat.com>
Sat, 27 Jun 2020 02:22:47 +0000 (22:22 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 27 Jun 2020 02:22:47 +0000 (22:22 -0400)
Take ordering of cursor_position and selection_bound
into account when copying text to the clipboard, and
ensure that both orders work the same.

Fixes: #2898
gtk/gtktext.c

index 1ba21144c17a0ffc2741ab9d52c40e672f124f6c..3dda4162cd4de12f78fb811df5db5b301f01a006 100644 (file)
@@ -4025,7 +4025,11 @@ gtk_text_copy_clipboard (GtkText *self)
           return;
         }
 
-      str = gtk_text_get_display_text (self, priv->selection_bound, priv->current_pos);
+      if (priv->selection_bound < priv->current_pos)
+        str = gtk_text_get_display_text (self, priv->selection_bound, priv->current_pos);
+      else
+        str = gtk_text_get_display_text (self, priv->current_pos, priv->selection_bound);
+
       gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (self)), str);
       g_free (str);
     }